package kr.co.choongang;

import java.io.IOException;
import java.io.Reader;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class IBoardDAO {
	private static SqlMapClient sqlMapper;

	public IBoardDAO() {
	}

	static {
		try {
			Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
			sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
			System.out.println("sqlMapper" + sqlMapper);
			reader.close();
		} catch (IOException e) {
			throw new RuntimeException(
					"Something bad happened while building the SqlMapClient instance."
							+ e, e);
		}
	}

/*	public List findAll() {
		try {
			List list = sqlMapper.queryForList("selectItem");
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public Item selectOne(Integer item_ID) {
		Item item = null;

		try {
			item = (Item) sqlMapper.queryForObject("selectOne", item_ID);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return item;
	}
	public ArrayList<Item> selectName(String item_Name) {
		ArrayList<Item> item = null;

		try {
			item = (ArrayList<Item>) sqlMapper.queryForList("selectName", item_Name);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return item;
	}
	public User selecttwo(String user_id) {
		User user = null;

		try {
			user = (User) sqlMapper.queryForObject("selecttwo", user_id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
	}

	public void insertUser(User userDto) {
		User user = null;

		try {
			sqlMapper.insert("insertUser", userDto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public User updateUser(User userDto) {
		User user = null;

		try {
			sqlMapper.update("updateUser", userDto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
	}

	public void insertSale(Sale sale) {

		try {
			sqlMapper.insert("insertSale", sale);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public List<Sale> findMaxSaleId() {

		try {
			List<Sale> list = (List<Sale>) sqlMapper.queryForList("selectSale");
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public void insertSaleLine(SaleLine saleline) {
		try {
			sqlMapper.insert("insertSaleLine", saleline);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void insertItem(Item item) {
		try {
			sqlMapper.insert("insertItem", item);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public Item updateItem(Item itemDto) {
		Item item = null;
		try {
			sqlMapper.update("updateItem", itemDto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return item;
	}
	
	public void deleteboard(Integer board_no) {
		try {
			sqlMapper.delete("deleteboard", board_no);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public Item selectPicture(Integer item_ID) {
		Item item = null;

		try {
			item = (Item) sqlMapper.queryForObject("selectPicture", item_ID);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return item;
	}*/
	
	public List<Board> selectBoard() {

		try {
			List<Board> list =  sqlMapper.queryForList("selectBoard");
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	

	public void insertboard(Board boardDto) {
		try {
			sqlMapper.insert("insertboard", boardDto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public Board selectfour(Integer board_no) {
		Board board = null;

		try {
			board = (Board) sqlMapper.queryForObject("selectfour", board_no);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return board;
	}
	public Board updateReadCount(Integer board_no) {
		Board board = null;
		try {
			sqlMapper.update("updateReadCount", board_no);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return board;
	}
	public Board updateboard(Board boardDto) {
		Board board = null;
		try {
			sqlMapper.update("updateboard", boardDto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return board;
	}
	public void insertcomment(Board boardDto) {
		try {
			sqlMapper.insert("insertcomment", boardDto);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public void deleteboard(Integer board_no) {
		try {
			sqlMapper.delete("deleteboard", board_no);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public ArrayList<Board> selecttitle(String board_title) {
		ArrayList<Board> board = null;

		try {
			board =  (ArrayList<Board>) sqlMapper.queryForList("selecttitle", board_title);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return board;
	}
	
	
}
